package scalapackage

/**
  * Created by Germmy on 2018/3/26.
  */
class ApplyTest(var name:String,var age:Int,var faceValue : Int) {//为啥不加var,applytest就点不出来？

}



object ApplyTest{

  //为啥我的apply无提示？是版本太旧？
  def apply(name:String,age:Int,faceValue:Int):ApplyTest=new ApplyTest(name,age,faceValue)


  def unapply(applytest:ApplyTest):Option[(String,Int,Int)]={//unapply必须小写
    if(applytest==null){
      None
    }else{
      Some(applytest.name,applytest.age,applytest.faceValue)
    }
  }



}


object  ApplyMain{

  def main(args: Array[String]) {


   var applyTest=ApplyTest("ningning",24,90)


    applyTest match {
      case ApplyTest("ningning",age,faceValue)=>println(s"faceValue:$faceValue")//这行可以下面这行对调，这样可以观察到效果
      case ApplyTest(name,zhangsan,faceValue)=>println(s"age:$zhangsan")//我觉得name,zhangsan,faceValue,就是option的返回值
      case _ =>println("No match")
    }



  }

}
